﻿// (c) Copyright Fernando Cerqueira.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;
using System.Windows.Media;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

// ReSharper disable CheckNamespace
namespace WindowsPhoneCommands
// ReSharper restore CheckNamespace
{
    public static class VsTheming
    {

        public static SolidColorBrush GetColorError()
        {
            return Brushes.Red;
        }

        public static SolidColorBrush GetWindowText()
        {
            const int color = (int)__VSSYSCOLOREX3.VSCOLOR_WINDOWTEXT;
            return SolidColorBrushFromWin32Color(GetWin32Color(color));
        }

        public static SolidColorBrush GetWindowDisabledText()
        {
            const int color = (int)__VSSYSCOLOREX3.VSCOLOR_GRAYTEXT;
            return SolidColorBrushFromWin32Color(GetWin32Color(color));
        }

        public static SolidColorBrush GetWindowHighlightText()
        {
            const int color = (int)__VSSYSCOLOREX3.VSCOLOR_HIGHLIGHT;
            return SolidColorBrushFromWin32Color(GetWin32Color(color));
        }

        public static SolidColorBrush GetDialogBackground()
        {
            const int color = (int)__VSSYSCOLOREX.VSCOLOR_PROJECTDESIGNER_TAB_BACKGROUND_GRADIENTBEGIN;
            return SolidColorBrushFromWin32Color(GetWin32Color(color));
        }

  
        private static uint GetWin32Color(int color)
        {
            uint win32Color = 0;
            var shell = ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShell)) as IVsUIShell2;
            if (shell != null) shell.GetVSSysColorEx(color, out win32Color);
            return win32Color;
        }

        private static SolidColorBrush SolidColorBrushFromWin32Color(uint win32Color)
        {
            byte[] bytes = BitConverter.GetBytes(win32Color);
            return new SolidColorBrush(Color.FromArgb(0xFF, bytes[0], bytes[1], bytes[2]));
        }
    }
}
